import pymysql
import pandas as pd
from com.atzl.functions.accounting.sql import UpDateData
from com.atzl.functions.accounting.sql.UpDateData import UpDateDataForDataBase
from com.atzl.functions.accounting.sql.QueryData import QueryDataByBase
from com.atzl.functions.accounting.func.Logs import CheckLogs


# 修改报价模块
class UpdatePrice(CheckLogs):


    # 获取财务报价数据库中所有的表名
    def get_all_price_table_name(self):
        conn = self.creat_conn()
        cur = conn.cursor(cursor=pymysql.cursors.DictCursor)
        sql = UpDateData.get_all_table()
        cur.execute(sql)
        data = cur.fetchall()
        data = pd.DataFrame(data)
        data = data['TABLE_NAME']
        cur.close()
        conn.close()
        return data

    # 获取财务西北超标报价数据库中所有的表名
    def get_nw_all_price_table_name(self):
        conn = self.creat_conn()
        cur = conn.cursor(cursor=pymysql.cursors.DictCursor)
        sql = UpDateData.get_nw_all_table()
        cur.execute(sql)
        data = cur.fetchall()
        data = pd.DataFrame(data)
        data = data['TABLE_NAME']
        cur.close()
        conn.close()
        return data


    # 获取报价表根据客户工号
    def get_price_data(self, obj_id):
        conn = self.creat_conn()
        cur = conn.cursor(cursor=pymysql.cursors.DictCursor)
        sql = QueryDataByBase.get_pricebyobjid(obj_id)
        cur.execute(sql)
        data = cur.fetchall()
        data = pd.DataFrame(data)
        cur.close()
        conn.close()
        return data

    # 获取西北超标报价表根据客户工号
    def get_nw_price_data(self, obj_id):
        conn = self.creat_conn()
        cur = conn.cursor(cursor=pymysql.cursors.DictCursor)
        sql = QueryDataByBase.get_nw_pricebyobjid(obj_id)
        cur.execute(sql)
        data = cur.fetchall()
        data = pd.DataFrame(data)
        cur.close()
        conn.close()
        return data


    # 模糊查询
    def get_like_names_table(self, like_name):
        conn = self.creat_conn()
        cur = conn.cursor(cursor=pymysql.cursors.DictCursor)
        sql = UpDateDataForDataBase.get_like_name_table(like_name)
        cur.execute(sql)
        data = cur.fetchall()
        data = pd.DataFrame(data)
        data = data['TABLE_NAME']
        cur.close()
        conn.close()
        return data


    # # 删除报价表根据表名
    # def del_table_by_name(self, by_name):
    #     conn = self.creat_conn()
    #     cur = conn.cursor(cursor=pymysql.cursors.DictCursor)
    #     sql = UpDateDataForDataBase.del_pricetableby_name(by_name)
    #     cur.execute(sql)